package com.fitz.util;

public class CovertUtil {

    private CovertUtil() {
    }

    public static Object convert(String value, Class<?> type) {
        Object result = null;
        try {
            if (Integer.TYPE.equals(type) || Integer.class.equals(type)) {
                result = Integer.parseInt(value);
            } else if (Long.TYPE.equals(type) || Long.class.equals(type)) {
                result = Long.parseLong(value);
            } else if (Short.TYPE.equals(type) || Short.class.equals(type)) {
                result = Short.parseShort(value);
            } else if (Double.TYPE.equals(type) || Double.class.equals(type)) {
                result = Double.parseDouble(value);
            } else if (Float.TYPE.equals(type) || Float.class.equals(type)) {
                result = Float.parseFloat(value);
            } else if (Boolean.TYPE.equals(type) || Boolean.class.equals(type)) {
                result = Boolean.parseBoolean(value);
            } else {
                //TODO 还有其他类型（比如BigDecimal等）自己实现
                result = type.cast(value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
